<div class="layui-fluid layui-anim febs-anim" id="seabusinesses-student" lay-title="学生公海">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="seabusinesses-table-form">
                        <fieldset class="layui-elem-field layui-field-title" style="">
                            <legend style="font-size: 15px; font-weight: bolder;">批量查询</legend>
                        </fieldset>
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">批次</label>
                                        <div id="seabatch" class="layui-input-inline"></div>
                                        <label class="layui-form-label layui-form-label-sm">院校</label>
                                        <div id="seacollege" class="layui-input-inline"></div>
                                        <label class="layui-form-label layui-form-label-sm">专业</label>
                                        <div id="seamajor" class="layui-input-inline"></div>
                                        <label class="layui-form-label layui-form-label-sm">层次</label>
                                        <div class="layui-input-inline">
                                            <select name="level" id="seaidlevel">
                                                <option value=""></option>
                                                <option value="1">专升本</option>
                                                <option value="3">高起专</option>
                                                <option value="2">高起本</option>
                                            </select>
                                        </div>
                                        <label class="layui-form-label layui-form-label-sm">阶段</label>
                                        <div class="layui-input-inline">
                                            <select id="seaidstage" name="stageId">
                                                <option value=""></option>
                                                <option value="14">考前</option>
                                                <option value="15">在籍</option>
                                                <option value="16">逾期毕业</option>
                                                <option value="17">已毕业</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <fieldset class="layui-elem-field layui-field-title" style="">
                            <legend style="font-size: 15px; font-weight: bolder;">精准查询</legend>
                        </fieldset>
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">姓名</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="stuName" autocomplete="off" class="layui-input"
                                                   id="seastuidstuname">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">身份证</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="identity" autocomplete="off" class="layui-input"
                                                   id="seastuididentity">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">电话</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="tel" autocomplete="off" class="layui-input"
                                                   id="seastuidtel">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action"
                                     id="seastuquery">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action"
                                     id="seastureset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                            </div>
                        </div>
                        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                            <div class="layui-row">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action"
                                     id="seamovtorecycle">
                                    <i class="layui-icon layui-icon-reload">移入回收站</i>
                                </div>
                            </div>
                        </blockquote>
                    </form>
                    <table lay-filter="seastudentTable" lay-data="{id: 'seastudentTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="sea-option">
    <a lay-event="seadetail" title="查看详情"><i
            class="layui-icon febs-edit-area febs-green">&#xe7a5;</i></a>
    <!--<a lay-event="edit"><i-->
    <!--class="layui-icon febs-edit-area febs-blue">&#xe7a4;</i></a>-->
    <!--<a lay-event="del"><i class="layui-icon febs-edit-area febs-red">&#xe7f9;</i></a>-->
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'form', 'table', 'febs', 'xmSelect'], function () {
        let $ = layui.jquery,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            dropdown = layui.dropdown,
            $view = $('#seabusinesses-student'),
            $query = $view.find('#seastuquery'),
            $reset = $view.find('#seastureset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createDate', type: null},
            seabatchSelect,
            seamajorSelect,
            seaeamXmSelect,
            tableIns;
        form.render();
        initTable();//大列表
        setseaeamXmSelect();
        setseamajorSelect();
        setseabatchSelect();

        function setseabatchSelect() {
            seabatchSelect = xmSelect.render({
                el: '#seabatch',
                //toolbar: {show: true},
                name: 'batchId',
                filterable: true,
                radio: true,
                theme: {
                    color: '#32c787',
                },
                model: {
                    label: {
                        type: 'text',
                        text: {
                            //左边拼接的字符
                            left: '',
                            //右边拼接的字符
                            right: '',
                            //中间的分隔符
                            separator: ', ',
                        },
                    }
                },
                prop: {
                    name: 'batchName',
                    value: 'id'
                },
                data: []
            });
            febs.get('/student/batchList', null, function (data) {
                seabatchSelect.update({
                    data: data.data,
                    autoRow: true,
                })
            });
        }


        $(".layui-input").keydown(function (e) {//当按下按键时
            if (e.which == 13) {//.which属性判断按下的是哪个键，回车键的键位序号为13
                $query.click();
            }
        });

        function setseaeamXmSelect() {
            seaeamXmSelect = xmSelect.render({
                el: '#seacollege',
                //toolbar: {show: true},
                name: 'collegeId',
                filterable: true,
                radio: true,
                theme: {
                    color: '#32c787',
                },
                model: {
                    label: {
                        type: 'text',
                        text: {
                            //左边拼接的字符
                            left: '',
                            //右边拼接的字符
                            right: '',
                            //中间的分隔符
                            separator: ', ',
                        },
                    }
                },
                prop: {
                    name: 'name',
                    value: 'id'
                },
                data: []
            });


            febs.get('/student/collegeList', null, function (data) {
                seaeamXmSelect.update({
                    data: data.data,
                    autoRow: true,
                })
            });
        }

        function setseamajorSelect() {
            seamajorSelect = xmSelect.render({
                el: '#seamajor',
                // toolbar: {show: true},
                name: 'majorId',
                filterable: true,
                radio: true,
                theme: {
                    color: '#32c787',
                },
                model: {
                    label: {
                        type: 'text',
                        text: {
                            //左边拼接的字符
                            left: '',
                            //右边拼接的字符
                            right: '',
                            //中间的分隔符
                            separator: ', ',
                        },
                    }
                },
                prop: {
                    name: 'fullName',
                    value: 'id'
                },
                data: []
            });

            febs.get('/student/majorList', null, function (data) {
                seamajorSelect.update({
                    data: data.data,
                    autoRow: true,
                })
            });
        }

        dropdown.render({
            elem: $view.find('.action-more'),
            click: function (name, elem, event) {
                let checkStatus = table.checkStatus('seastudentTable');
                if (name === 'add') {
                    febs.modal.open('新增院校', 'college/add', {
                        btn: ['提交', '重置'],
                        area: $(window).width() <= 750 ? '95%' : '50%',
                        yes: function (index, layero) {
                            $('#college-add').find('#submit').trigger('click');
                        },
                        btn2: function () {
                            $('#college-add').find('#reset').trigger('click');
                            return false;
                        }
                    });
                }
                if (name === 'delete') {
                    if (!checkStatus.data.length) {
                        febs.alert.warn('请选择需要删除的院校');
                    } else {
                        febs.modal.confirm('提示', '确定删除该院校？', function () {
                            let collegeIds = [];
                            layui.each(checkStatus.data, function (key, item) {
                                collegeIds.push(item.id)
                            });
                            deleteColleges(collegeIds.join(','));
                        });
                    }
                }
                if (name === 'export') {
                    let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
                    params.pageSize = $view.find(".layui-laypage-limits option:selected").val();
                    params.pageNum = $view.find(".layui-laypage-em").next().html();
                    febs.download(ctx + 'college/excel', params, '院校信息表.xlsx');
                }
            },
            options: [{
                name: 'add',
                title: '新增院校',
                perms: 'college:add'
            }, {
                name: 'delete',
                title: '删除院校',
                perms: 'college:delete'
            }, {
                name: 'export',
                title: '导出Excel',
                perms: 'college:export'
            }]
        });

        //当前人员的待办数量
        $(function () {
            $.ajax({
                type: "get"
            })
        })

        table.on('tool(seastudentTable)', function (obj) {
            let data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'seadetail') {
                febs.modal.view('院校信息', 'student/poolDetail/' + data.id, {
                    area: ['70%', '80%'],
                    tipsMore: true
                });
            }
            if (layEvent === 'del') {
                febs.modal.confirm('提示', '确定删除该院校？', function () {
                    deleteColleges(data.id);
                });
            }
            if (layEvent === 'edit') {
                febs.modal.open('修改院校', 'college/update/' + data.id, {
                    area: $(window).width() <= 750 ? '90%' : '50%',
                    btn: ['提交', '取消'],
                    yes: function (index, layero) {
                        $('#college-update').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
        });

        table.on('sort(seastudentTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        $query.on('click', function () {
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });


        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            tableIns.reload({where: getQueryParams(true), page: {curr: 1}, initSort: sortObject});
            var collegeIds = new Array();
            collegeIds.push('');
            seaeamXmSelect.setValue(collegeIds);
            var batchIds = new Array();
            batchIds.push('');
            seabatchSelect.setValue(batchIds);
            var majorIds = new Array();
            majorIds.push('');
            seamajorSelect.setValue(majorIds);
        });

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'seastudentTable',
                url: ctx + 'student/list',
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: '序号', minWidth: 80},
                    {field: 'stuName', title: '姓名', minWidth: 80},
                    {field: 'collegeName', title: '院校', minWidth: 80},
                    {field: 'batchName', title: '批次', minWidth: 80},
                    {field: 'levelname', title: '层次', minWidth: 80},
                    {
                        field: 'stageId', title: '阶段', width: 110,
                        templet: function (obj) {
                            var exep;
                            if (obj.stageId == 14) {
                                exep = '考前';
                            } else if (obj.stageId == 15) {
                                exep = '在籍';
                            } else if (obj.stageId == 16) {
                                exep = '逾期毕业';
                            } else if (obj.stageId == 17) {
                                exep = '已毕业';
                            }
                            return exep;
                        }
                    },
                    {field: 'majorName', title: '专业', minWidth: 80},
                    {field: 'className', title: '班级名称', minWidth: 80},
                    {field: 'userName', title: '班主任', minWidth: 80},
                    {field: 'tel', title: '电话', minWidth: 80},
                    {field: 'identity', title: '身份证', minWidth: 80},
                    {title: '操作', toolbar: '#sea-option', minWidth: 140},
                ]],

            });
        }

        function getQueryParams(flag) {
            let params = $searchForm.serializeJson();
            return params;
        }

        $("#seamovtorecycle").click(function () {
            let checkStatus = table.checkStatus('seastudentTable');
            let studentIds = [];
            layui.each(checkStatus.data, function (key, item) {
                studentIds.push(item.id)
            });
            if (studentIds.length > 0) {
                febs.modal.confirm('提示', '确定移入回收站吗？', function () {
                    recycleStudent(studentIds.join(','));
                });
            } else {
                febs.alert.warn('请选择学生!');
            }
        });

        function recycleStudent(studentIds) {
            febs.get(ctx + 'student/moveToRecycle/' + studentIds, null, function () {
                febs.alert.success('学生回收成功');
                $query.click();
            });
        };
    });


</script>

